import taxiTimeSelector from './taxiTimeSelector';
import taxiRedMoneySelector from './taxiRedMoneySelector';
import taxiModifyRedMoneySelector from './taxiModifyRedMoneySelector';
import taxiPayTypeSelector from './taxiPayTypeSelector';
import SearchBox from './search/SearchBox';
import taxiEvaluateSelector from './taxiEvaluateSelector';
import taxiSeeEvaluateSelector from './taxiSeeEvaluateSelector';
import store from '@/store';
import router from '@/router';
import Vue from 'vue';
const TimeConstructor = Vue.extend(taxiTimeSelector);
const TaxiRedMoneySelector = Vue.extend(taxiRedMoneySelector);
const TaxiModifyRedMoneySelector = Vue.extend(taxiModifyRedMoneySelector);
const TaxiPayTypeSelector = Vue.extend(taxiPayTypeSelector);
const TaxiEvaluateSelector = Vue.extend(taxiEvaluateSelector);
const TaxiSeeEvaluateSelector = Vue.extend(taxiSeeEvaluateSelector);
const SearchBoxConstructor = Vue.extend(SearchBox);
function createVM(constructor, opt) {
  return new Promise((resolve, reject) => {
    let params = {
      value: true
    };
    Object.assign(params, opt);
    let vm = new constructor({
      propsData: params,
      store,
      router
    }).$mount();
    if (vm) {
      vm.$on('cancel', () => {
        vm.$destroy();
        reject();
      });
      vm.$on('submit', data => {
        resolve(data);
        vm.$destroy();
      });
    }
  });
}
const Popup = {
  createTimeSelector() {
    return createVM(TimeConstructor);
  },
  createRedMoneySelector() {
    return createVM(TaxiRedMoneySelector);
  },
  createModifyRedMoneySelector() {
    return createVM(TaxiModifyRedMoneySelector);
  },
  createPayTypeSelector() {
    return createVM(TaxiPayTypeSelector);
  },
  createEvaluateSelector() {
    return createVM(TaxiEvaluateSelector);
  },
  createSeeEvaluateSelector() {
    return createVM(TaxiSeeEvaluateSelector);
  },
  selectStartPosition() {
    return createVM(SearchBoxConstructor, { isStart: true });
  },
  selectEndPosition() {
    return createVM(SearchBoxConstructor, { isStart: false });
  }
};
export default Popup;
